package service;

import java.util.ArrayList;
import java.util.HashMap;

import dao.WishDAO;
import dto.ListWishPageDTO;
import dto.PagingDTO;
import dto.ProductDTO;
import dto.WishDTO;

public class WishManageService {
	private WishDAO dao;
	public WishManageService(WishDAO dao) {
		this.dao = dao;
	}
	public void insertWish(WishDTO wishDTO){
		wishDTO.setWishNo(dao.selectWishNo());
		dao.insertWish(wishDTO);
	}
	public void deleteWish(int productId, String memberId){
		HashMap map = new HashMap();
		map.put("productId", productId);
		map.put("memberId", memberId);
		dao.deleteWish(map);
	}
	public ProductDTO selectProductByProduct(int productId){
		return dao.selectProductByProductId(productId);
	}
	public ArrayList<WishDTO> selectWishByMember(String memberId){
		return dao.selectWishById(memberId);
	}
	
	public ArrayList<ProductDTO> selectProductByMemberId(String memberId){
		ArrayList<WishDTO> wishList = dao.selectWishById(memberId);
		ArrayList<ProductDTO> productList = new ArrayList<ProductDTO>();
		
		for(int i =0; i<wishList.size(); i++){
			int productId = wishList.get(i).getProductId();
			productList.add(dao.selectProductByProductId(productId));
		}
		return  productList;
	}
	
	public WishDTO selectWishByIds(int productId, String memberId){
		HashMap map = new HashMap();
		map.put("productId", productId);
		map.put("memberId", memberId);
		return dao.selectWishByIds(map);
	}
	
	public ListWishPageDTO selectWishListByPage(int page ,String memberId){
		ListWishPageDTO listWishPageDTO = null;
		ArrayList<ProductDTO> wishList = dao.selectWishListByPaging(page);
		int total = dao.selectCountWish(memberId);
		PagingDTO pdto = new PagingDTO(total, page);
		listWishPageDTO = new ListWishPageDTO(wishList, pdto);
		return listWishPageDTO;
	}
	
}
